package com.simon.train.member.controller;

import com.simon.train.common.Result.Result;
import com.simon.train.member.dto.MemberDto;
import com.simon.train.member.dto.MemberLoginDto;
import com.simon.train.member.dto.MemberSendCodeDto;
import com.simon.train.member.service.MemberService;
import com.simon.train.member.vo.MemberLoginVO;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/member")
public class MemberController {

    @Resource
    private MemberService memberService;

    /**
     * 仅用于测试的代码
     * @return
     */
    @GetMapping("/count")
    public Result<Integer> count() {
        int count = memberService.count();
        Result<Integer> res = new Result<>();
        res.setContent(count);
        return res;
    }

    /**
     * 会员用户注册接口开发
     * 目前无用
     * @param memberDto
     * @return
     */
    @PostMapping("/register")
    public Result<Long> register(@Valid MemberDto memberDto){
        Result<Long> res = new Result<>();
        res.setContent(memberService.register(memberDto));
        return res;
    }

    /**
     * 发送短信验证码接口
     * 前端登录or注册 二合一的接口
     * @param memberSendCodeDto
     * @return
     */
    @PostMapping("/sendCode")
    public Result<Long> SendCode(@Valid @RequestBody MemberSendCodeDto memberSendCodeDto){
        memberService.SendCode(memberSendCodeDto);
        return new Result<>();
    }


    /**
     * 用户登录接口
     * @param memberLoginDto
     * @return
     */
    @PostMapping("/login")
    public Result<MemberLoginVO> Login(@Valid @RequestBody MemberLoginDto memberLoginDto){
        MemberLoginVO vo = memberService.Login(memberLoginDto);
        return new Result<>(vo);
    }

}
